package com.example.flag03;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

public class MineItemAdapter extends ArrayAdapter<MineItem> {
    private int resourceId;

    public MineItemAdapter(Context context, int resourcedId , List<MineItem>objects) {
        super(context, resourcedId,objects);
        this.resourceId = resourcedId;
    }

    @Override
    public View getView(int position, View convertView,ViewGroup parent) {
        // 获取当前项的MineItem实例
        MineItem item = (MineItem) getItem(position);
        //获取子视图控件实例
        View view = LayoutInflater.from(getContext()).inflate(resourceId, parent, false);
        //获取该布局内的图片视图
        ImageView more = (ImageView) view.findViewById(R.id.more);
        //获取该布局内的文本视图
        TextView text= (TextView) view.findViewById(R.id.text);
        TextView number=(TextView)view.findViewById(R.id.number);
        //为图片视图设置图片资源
        if(item.getNumber()==-1) {
            more.setImageResource(item.getImageId());
        }
        //为文本视图设置文本内容
        text.setText(item.getText());
        if(item.getNumber()!=-1) {
            number.setText(String.valueOf(item.getNumber()));
        }
        return view;
    }
}
